package com.sample.plove.database.service.impl;

import com.sample.plove.database.dao.AccesstokenRepository;
import com.sample.plove.database.model.AccessTokenEntity;
import com.sample.plove.database.service.AccessToeknServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

/**
 * PackageName:com.sample.plove.database.service.impl
 * Author:Administrator
 * Time:23:48
 * Date:2019/5/16
 * Describe:操作AccessToken数据的实现类
 */
@Component
@Repository
public class AccessTokenServerImpl implements AccessToeknServer {
    private static final Logger log = LoggerFactory.getLogger("AccessToken");
    @Autowired
    public AccesstokenRepository accesstokenRepository;
    @Override
    public void addAccessToken(AccessTokenEntity entity) {
    accesstokenRepository.save(entity);
    }

    @Override
    public Optional<AccessTokenEntity> findAccessTokenById(int id) {
        log.info("findAccessTokenById");
        return accesstokenRepository.findById(id);
    }

    @Override
    public List<AccessTokenEntity> findAccessToken() {
        log.info("findAccessToken");
        return accesstokenRepository.findAll();
    }

    @Override
    public void updateAccessToken(AccessTokenEntity entity) {
        log.info("updateAccessToken");
    accesstokenRepository.save(entity);
    }

    @Override
    public void removeAccessToken(AccessTokenEntity entity) {
        log.info("removeAccessToken");
        accesstokenRepository.delete(entity);
    }

    @Override
    public void cleanAccessToken() {
        log.info("cleanAccessToken");
        accesstokenRepository.deleteAll();
    }
}
